package com.demo.producer;

import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author wangfeng
 * @Description
 * @Date 2021/11/25
 **/
@Service
public class MqSender {
	@Resource
	private RocketMQTemplate rocketMQTemplate;

	public void send(String topic,String message){
		rocketMQTemplate.getProducer().setDefaultTopicQueueNums(1);
		//save to DB
		rocketMQTemplate.convertAndSend(topic,message);
	}

	public void send(String topic, String tags, String keys, String body){
		Message message = new Message(topic, tags, keys, body.getBytes());
		try {
			rocketMQTemplate.getProducer().send(message);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


}
